/**
 * 自定义formUpLoad组件
 * by wangjianjun
 * create 2021-10-29
 */
import React from 'react';
import PropTypes from 'prop-types';
import { QuestionCircleOutlined } from '@ant-design/icons';
import { Form } from '@ant-design/compatible';
import '@ant-design/compatible/assets/index.css';
import { Input, Tooltip } from 'antd';
import { FormItemLayout } from '../formPub';
import { UploadC } from '../../../comps';

const FormUpLoadC = (props) => {
  const {
    styleRow,
    width,
    form,
    title,
    info,
    helper,
    formItemLayout,
    showTitle,
    labalWrap,
    style,
    upLoadType,
    action,
    data,
    showUploadList,
    onUpload,
    onRef,
    multiple,
    upLoadTitle,
    disabled,
    fileListLoading,
    loading,
    value,
    remove,
    isDowm,
    isDelete,
    accept,
    toolTip,
  } = props;
  const { getFieldDecorator } = form;
  return (
    <Form.Item
      {...formItemLayout}
      className={labalWrap ? 'labalWrap' : ''}
      label={
        showTitle ? (
          helper ? (
            <span>
              {title}&nbsp;
              <Tooltip title={helper}>
                <QuestionCircleOutlined />
              </Tooltip>
            </span>
          ) : (
            <span>{title}</span>
          )
        ) : null
      }
    >
      {/* <UploadC
          type={1}
          action={'api/v1/attach/upload2Ce'}
          showUploadList={true}
          data={{
              userCode: '014205',
              busiId: 'fda1f9619a064a579ca23f2e73aa523e',
              busiType: 'BUSI_TYPE_TYLC',
          }}
          onUpload={(e) => { console.log(e, '111') }}
          // onRef={e => this.setState({ ref: e })}
      /> */}

      <UploadC
        type={upLoadType}
        action={action}
        toolTip={toolTip}
        showUploadList={showUploadList}
        data={data}
        multiple={multiple}
        onUpload={onUpload}
        onRef={onRef}
        title={upLoadTitle}
        disabled={disabled}
        fileListLoading={fileListLoading}
        loading={loading}
        value={value}
        remove={remove}
        isDowm={isDowm}
        isDelete={isDelete}
        accept={accept}
        styleRow={styleRow ? styleRow : null}
        width={width}
      />
    </Form.Item>
  );
};

// props类型
FormUpLoadC.propsTypes = {
  style: PropTypes.object, // 自定义样式
  labalWrap: PropTypes.bool, // 支持标题换行
  form: PropTypes.object, // form对象
  title: PropTypes.string, // 显示名称
  info: PropTypes.string, // 文本内容
  helper: PropTypes.oneOfType([
    // 提示帮助信息
    PropTypes.string,
    PropTypes.element,
  ]),
  formItemLayout: PropTypes.object, // 布局
  disabled: PropTypes.bool, // 禁用
  showTitle: PropTypes.bool, // 是否展示输入框名称
  upLoadType: PropTypes.number, // type=1 自动上传使用默认接口，type = 2获奖文件流
  action: PropTypes.string, // 上传地址
  data: PropTypes.object, // 额外的参数
  showUploadList: PropTypes.bool, // 是否展示列表
  onUpload: PropTypes.func, // 上传成后的回调
  onRef: PropTypes.func, // 本组件的引用（可用来父组件调用内部方法）
  multiple: PropTypes.bool, // 是否支持多选
  upLoadTitle: PropTypes.string, // 显示名称
  fileListLoading: PropTypes.bool, // 文件列表加载状态
  loading: PropTypes.bool, // 按钮加载状态
  value: PropTypes.array, // 回填的数据 (格式：[{title:'',value:''},{title:'',value:''}])
  remove: PropTypes.func, // 删除调用
  isDowm: PropTypes.bool, // 是否允许下载
  isDelete: PropTypes.bool, // 是否允许删除
  accept: PropTypes.string, // 上传文件类型
};

// props默认值
FormUpLoadC.defaultProps = {
  title: '',
  info: '',
  helper: '',
  onChange: () => {},
  formItemLayout: FormItemLayout,
  showTitle: true,
  labalWrap: false, //默认title不换行
  upLoadType: 1, //默认自动上传
  action: 'gateway/file/maat-admin/file/upload', //上传地址
  data: {},
  showUploadList: true, //是否展示文件列表
  onUpload: () => {},
  onRef: () => {},
  multiple: false, // 默认false
  upLoadTitle: '上传附件', // 默认'上传附件'
  disabled: false, // 默认false
  fileListLoading: false, // 默认false
  loading: false, // 默认false
  value: null, // 默认null
  remove: () => {}, //删除调用
  isDowm: true, // 默认ture
  isDelete: true, // 默认ture
  accept: '', //默认可上传全部类型
};

export default FormUpLoadC;
